package com.example.smartcity_poverty.ui.AllService.YouthPost.activity

import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.text.Html
import com.example.smartcity_poverty.R
import com.example.smartcity_poverty.logic.network.AppApi
import com.example.smartcity_poverty.logic.network.ServiceNET.Companion.create
import kotlinx.android.synthetic.main.activity_list_show.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch

/**
 * 人才区域列表详细信息展示
 */
@Suppress("DEPRECATION")
class ListShowActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_list_show)
        tb.setNavigationOnClickListener { finish() }

        intent.getStringExtra("id")?.toInt().let {
            // 填充数据
            setIdShow(it!!)
        }

    }

    private fun setIdShow(id: Int) {
        GlobalScope.launch(Dispatchers.IO){
            create<AppApi>().getYhListDetail(
                getSharedPreferences("token", Context.MODE_PRIVATE).getString("token", "").toString(),
                id
            ).apply {
                if (this.code == 200){
                    this.data?.let {
                        runOnUiThread {
                            // 填充数据
                            lShowTitle.text = it.title
                            lShowUser.text = "作者: ${it.author}"
                            lShowTIme.text = "发布时间: ${it.createTime}"
                            lShowContent.text = Html.fromHtml(it.content)
                        }
                    }
                }
            }
        }
    }
}